/**
 * 功能描述�?
 */

define(function (require, exports, module) {
	var aw = require("ajaxwrapper");
	
    module.exports = {
            saveAction : function(widget){
            	if(!widget.get("form").valid()){
            		return false;
            	}
            	var formData = widget.get("form").getData();
            	var editGridData = widget.get("editgrid").getData();
            	var roomEditGridData = widget.get("roomeditgrid").getData();
            	for(var i = 0; i < roomEditGridData.length; i++){
            		if(typeof roomEditGridData[i].roomType != "string"){
            			roomEditGridData[i].roomType = roomEditGridData[i].roomType.pkRoomType;
            		}
            	}
            	for(var i = 0; i < editGridData.length; i++){
            		if(typeof editGridData[i].personalInfo.sex != "string"){
            			editGridData[i].personalInfo.sex = editGridData[i].personalInfo.sex.key;
            		}
            		if(editGridData[i].planItemGroup && typeof editGridData[i].planItemGroup != "string"){
            			editGridData[i].planItemGroup = editGridData[i].planItemGroup.pkPlanItemGroup;
            		}
            	}
            	var data = {
	            		planItemGroup : formData,
	    				signUpList : editGridData,
	    				pkSignList : widget.get("pkSignList"),
	    				signUpRoomTypeCounts:roomEditGridData
        		};
            	aw.saveOrUpdate("api/planitem/savealliance", aw.customParam(data), function(datas){
            		widget.show([".J-grid"]).hide([".J-form",".J-editgrid",".J-roomeditgrid"]);
            		widget.get("subnav").hide(["save", "return"]).show(["add","status", "startDate"]);
            		widget.get("grid").refresh();
            		widget.get("editgrid").setData([]);
            	})
            }
        };
});
